package com.changan.entity;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import java.io.Serializable;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

/**
 * <p>
 * 菜单表
 * </p>
 *
 * @author NieChangan
 * @since 2022-08-30
 */
@Getter
@Setter
@Accessors(chain = true)
@TableName("tb_menu")
@ApiModel(value = "Menu对象", description = "菜单表")
public class Menu extends Model<Menu> {

    @ApiModelProperty("菜单/按钮ID")
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    @ApiModelProperty("上级菜单ID")
    @TableField("parent_id")
    private Long parentId;

    @ApiModelProperty("菜单/按钮名称")
    @TableField("menu_name")
    private String menuName;

    @ApiModelProperty("菜单URL")
    @TableField("url")
    private String url;

    @ApiModelProperty("权限标识")
    @TableField("perms")
    private String perms;

    @ApiModelProperty("图标")
    @TableField("icon")
    private String icon;

    @ApiModelProperty("类型 0菜单 1按钮")
    @TableField("type")
    private String type;

    @ApiModelProperty("排序")
    @TableField("order_num")
    private Long orderNum;

    @ApiModelProperty("创建时间")
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    private Date createTime;

    @ApiModelProperty("修改时间")
    @TableField("modified_time")
    private Date modifiedTime;

    @ApiModelProperty("0：不可用，1：可用")
    @TableField("available")
    private Integer available;

    @ApiModelProperty("0:不展开，1：展开")
    @TableField("open")
    private Integer open;

    @ApiModelProperty("子菜单")
    @TableField(exist = false)
    private List<Menu> childMenus;

    /**
     * 对menu菜单进行排序
     * @return
     */
    public static Comparator<Menu> order(){
        Comparator<Menu> comparator = (o1, o2) -> {
            if(o1.getOrderNum() != o2.getOrderNum()){
                return (int) (o1.getOrderNum() - o2.getOrderNum());
            }
            return 0;
        };
        return comparator;
    }

    @Override
    public Serializable pkVal() {
        return this.id;
    }

}
